<?php
/**************************************************
* PluginLotto.com                                 *
* Copyrights (c) 2005-2010. iZAP                  *
* All rights reserved                             *
***************************************************
* @author iZAP Team "<support@izap.in>"
* @link http://www.izap.in/
* @version {version} $Revision: {revision}
* Under this agreement, No one has rights to sell this script further.
* For more information. Contact "Tarun Jangra<tarun@izap.in>"
* For discussion about corresponding plugins, visit http://www.pluginlotto.com/pg/forums/
* Follow us on http://facebook.com/PluginLotto and http://twitter.com/PluginLotto
 */

$poll = $vars['entity'];
$unique_id = func_generate_unique_id($poll->guid);

$session = func_get_session_byizap($poll->guid);
//$session = FALSE;
if($session) {
  echo elgg_view('output/result_only',array('entity' => $poll ));
} else {
  $url = func_set_href_byizap( array(
          'plugin' => GLOBAL_IZAP_POLL_PLUGIN,
          'page' => 'cal_poll',
          'page_owner' => $poll->getOwnerEntity()->username,
          'vars'=> array( $poll->guid ))).'/';
  ?>
<div class="izap_poll_container">
  <div id="<?php echo $unique_id?>" style="margin-top: 5px;">
      <?php
      for($i = 1; $i <= $poll->total_options; $i++) {
        $option_dec = 'option_' . $i;

        ?>
    <label class="izap_poll_click">
      <input type="radio" value="<?php echo $i?>" name="<?php echo $poll->guid."_"."izap_poll_radio" ?>" />
          <?php echo $poll->$option_dec;?>
      <br />
    </label>
        <?php
      }
      ?>
  </div>
</div>
<script type="text/javascript">
  $(document).ready(function(){
    $('input[name="<?php echo $poll->guid."_"."izap_poll_radio" ?>"]').click(function(){
      var option = $('input[name="<?php echo $poll->guid."_"."izap_poll_radio" ?>"]:checked').val();
      $('#<?php echo $unique_id?>').html('<?php echo elgg_echo('izap_poll:loading');?>');
      $('#<?php echo $unique_id?>').load('<?php echo $url?>' + option );
    });
  });
</script>
  <?php
}